# cmake_minimum_required(VERSION 3.10)
# project(JinlingFirstProject)
# set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)

# file(GLOB BASE_CPP_FILES "src/base/*.cpp")
# file(GLOB BASE_H_FILES "src/base/*.h")
# file(GLOB MAIN_CPP_FILES "src/main/*.cpp")

# set(SRC_FILES  
#     ${BASE_CPP_FILES}
#     ${BASE_H_FILES}
#     ${MAIN_CPP_FILES}
# )

# # 设置 JSONCpp 安装路径
# set(JSONCPP_INSTALL_DIR ${PROJECT_SOURCE_DIR}/lib/jsoncpp)

# # 编译 JSONCpp 为静态库（关键修正点）
# include(ExternalProject)
# ExternalProject_Add(
#     jsoncpp_project
#     SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/jsoncpp
#     BINARY_DIR ${CMAKE_BINARY_DIR}/jsoncpp-build
#     INSTALL_DIR ${JSONCPP_INSTALL_DIR}
#     CMAKE_ARGS
#         -DCMAKE_INSTALL_PREFIX=${JSONCPP_INSTALL_DIR}
#         -DCMAKE_BUILD_TYPE=Release
#         -DBUILD_STATIC_LIBS=ON    # 强制生成静态库
#         -DBUILD_SHARED_LIBS=OFF   # 禁用动态库
#     BUILD_COMMAND $(MAKE)         # 跨平台编译
#     INSTALL_COMMAND $(MAKE) install
# )

# # 创建导入的静态库目标（解决 UTILITY 冲突）
# add_library(jsoncpp STATIC IMPORTED GLOBAL)
# add_dependencies(jsoncpp jsoncpp_project)  # 确保先编译 JSONCpp

# # 设置库文件和头文件路径
# set_target_properties(jsoncpp PROPERTIES
#     IMPORTED_LOCATION ${JSONCPP_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX}
#     INTERFACE_INCLUDE_DIRECTORIES ${JSONCPP_INSTALL_DIR}/include
# )

# # 生成主可执行文件
# add_executable(tmms ${SRC_FILES})
# target_link_libraries(tmms PRIVATE jsoncpp)  # 链接 JSONCpp

# # 设置输出目录
# set_target_properties(tmms PROPERTIES
#     RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out_exe
# )


#Cursor:
#在这里使用add_subdirectory
cmake_minimum_required(VERSION 3.10)
project(my_app LANGUAGES CXX)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 子项目1: my_library_base
add_subdirectory(
    ../base/  #子集cmakelist的目录
    libs/my_library_base   #输出的构建目录
)
# 子项目2: my_library_network
add_subdirectory(
    ../network 
    libs/my_library_network
)

# 收集主项目源文件
# file(GLOB_RECURSE APP_SOURCES ./*.cpp)
set(APP_SOURCES 
   ./main.cpp  # 仅指定主入口文件
)

# 创建可执行文件
add_executable(my_app ${APP_SOURCES})

# 链接依赖库
target_link_libraries(my_app
    PRIVATE
    my_library_base    # 链接基础功能库
    my_library_network # 链接网络功能库
)


# 添加头文件搜索路径（确保主项目能找到子项目头文件）
target_include_directories(my_app
    PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/../my_library/my_library_base  # 基础库头文件路径
    ${CMAKE_CURRENT_SOURCE_DIR}/../my_library/my_library_network # 网络库头文件路径
)

# （可选）添加编译选项
target_compile_options(my_app PRIVATE -O2)